package com.hongxun.project.assets.iPullLine.service;

import java.util.List;
import java.util.UUID;

import com.hongxun.common.utils.bean.BeanUtils;
import com.hongxun.project.assets.iBoxes.domain.IBoxes;
import com.hongxun.project.assets.pBoxes.domain.PBoxes;
import com.hongxun.project.assets.pPullLine.domain.PPullLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.iPullLine.mapper.IPullLineMapper;
import com.hongxun.project.assets.iPullLine.domain.IPullLine;
import com.hongxun.project.assets.iPullLine.service.IIPullLineService;
import com.hongxun.common.utils.text.Convert;

/**
 * 拉线 服务层实现
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class IPullLineServiceImpl implements IIPullLineService 
{
	@Autowired
	private IPullLineMapper iPullLineMapper;

	/**
     * 查询拉线信息
     * 
     * @param id 拉线ID
     * @return 拉线信息
     */
    @Override
	public IPullLine selectIPullLineById(String id)
	{
	    return iPullLineMapper.selectIPullLineById(id);
	}
	
	/**
     * 查询拉线列表
     * 
     * @param iPullLine 拉线信息
     * @return 拉线集合
     */
	@Override
	public List<IPullLine> selectIPullLineList(IPullLine iPullLine)
	{
	    return iPullLineMapper.selectIPullLineList(iPullLine);
	}
	
    /**
     * 新增拉线
     * 
     * @param iPullLine 拉线信息
     * @return 结果
     */
	@Override
	public int insertIPullLine(IPullLine iPullLine)
	{
		iPullLine.setId(UUID.randomUUID().toString());
	    return iPullLineMapper.insertIPullLine(iPullLine);
	}
	
	/**
     * 修改拉线
     * 
     * @param iPullLine 拉线信息
     * @return 结果
     */
	@Override
	public int updateIPullLine(IPullLine iPullLine)
	{
	    return iPullLineMapper.updateIPullLine(iPullLine);
	}

	/**
     * 删除拉线对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteIPullLineByIds(String ids)
	{
		return iPullLineMapper.deleteIPullLineByIds(Convert.toStrArray(ids));
	}



	public void file(List<PPullLine> pPullLine) {
		for (PPullLine p : pPullLine) {
			if (p.getDatastate().equals("删除")) {
				deleteIPullLineByIds(p.getId());
			} else {
				IPullLine i = new IPullLine();
				BeanUtils.copyBeanProp(i, p);
				if (selectIPullLineById(p.getId()) != null) {
					updateIPullLine(i);
				} else {
					iPullLineMapper.insertIPullLine(i);
				}
			}
		}
	}
}
